<template>
  <view class="page-prev-p1">
    <view class="tit-box">
      <view class="row-1">
        <image class="img" :src="staticImgs.baseTip" mode="widthFix"></image>
      </view>
      <view class="row-2">
        <image class="img" :src="staticImgs.qstTip" mode="widthFix"></image>
      </view>
    </view>

    <view class="main-wrapper">
      <view class="scroll-opts-pos" v-if="!reRender">
        <picker-view :mask-style="mask" indicator-class="scroll-act-select" :value="value" @change="bindChange"
          class="picker-view">
          <picker-view-column>
            <view class="opt-item-type-2" :class="{'opt-item-act': age.val == actAge}" v-for="(age,index) in optArr"
              :key="age.val">{{age.txt}}
            </view>
          </picker-view-column>
        </picker-view>
      </view>
      <view class="abs-act-box"></view>
    </view>

    <view class="btn-pos">
      <image @click="prevHandle" class="img" :src="staticImgs.prevBtn" mode="widthFix"></image>
      <image @click="nextHandle" class="img" :src="staticImgs.nextBnt" mode="widthFix"></image>
    </view>
  </view>
</template>

<script>
  import {
    debounce
  } from 'lodash'
  export default {
    props: {
      act: null,
      opts: null
    },
    data() {
      return {
        staticImgs: {
          baseTip: this.imgBaseURL + "/scl/checkup-sexuality/prev-p1/base-tip.png",
          qstTip: this.imgBaseURL + "/scl/checkup-sexuality/prev-p2/qst-tip.png",
          bg: this.imgBaseURL + "/scl/checkup-sexuality/prev-p1/bg.jpg",
          nextBnt: this.imgBaseURL + "/scl/checkup-sexuality/prev-p1/next-qst.png",
          prevBtn: this.imgBaseURL + "/scl/checkup-sexuality/prev-p1/prev-qst.png",
          actBoxBg: this.imgBaseURL + "/scl/checkup-sexuality/prev-p1/act-box-bg.png",
        },
        optArr: [],
        actAge: null,
        value: [],
        mask: `background:none;` ,// 去掉遮罩层背景色
        reRender:false,
      }
    },
    watch: {
      act: {
        handler(val, oldVal) {
          console.log(val, '====val')
          if(val){
            this.actAge = val
          }
        },
        immediate: true
      },
      opts: {
        handler(val, oldVal) {
          if (val && val.length > 0) {
            const tmoptArr = val.map(item => {
              return {
                img: item.imageURL,
                txt: item.text,
                val: item.key,
              }
            })
            this.optArr = tmoptArr
            
            if(this.actAge){
              this.value[0] = tmoptArr.findIndex(item=>item.val == this.actAge)
            }else{
              this.actAge = tmoptArr[0].val
              this.value[0] = 0//tmoptArr[0].val
            }
            
            this.value[0] = parseInt(this.value[0])
            
            this.reRender = true
            this.$nextTick(()=>{
              this.reRender = false
            })
            
            console.log(this.actAge,'===this.actAge')
            console.log(tmoptArr, '==opts====val')
            console.log(this.value,'===this.value[0]==')
          }
        },
        immediate: true
      }
    },
    methods: {
      bindChange(e) {
        const val = e.detail.value
        console.log(val[0],'-===val[0]')
        console.log(this.value,'=====this.value===')
        console.log(this.optArr[val[0]],'===this.value[val[0]]')
        this.actAge = this.optArr[val[0]].val
        console.log(val,'===val')
      },
      nextHandle() {
        this.$emit('next', this.actAge, 2)
      },
      prevHandle() {
        this.$emit('prev')
      }
    }
  }
</script>

<style lang="scss" scoped>
  .scroll-inner-wrapper {
    display: flex;
    flex-direction: column;
    // row-gap: 16rpx;

    height: 516rpx;
    align-items: center;
    z-index: 2;
  }

  /deep/.scroll-act-select {
    // background-color: red;
    // background-color: #05B7B4;

    border: none;
    color: #073563;
    z-index: 1;
    height: 90rpx;
    // background: linear-gradient( 90deg, rgba(255,255,255,0) 0%, #FFFFFF 58%, rgba(255,255,255,0) 100%);
  }

  .opt-item-type-2 {
    font-family: PingFang-SC, PingFang-SC;
    font-weight: 500;
    font-size: 36rpx;
    // color: #FFFFFF;
    // line-height: 90rpx;
    height: 90rpx !important;
    text-align: center;
    font-style: normal;
    // background-color: rgba(0, 0, 0, 0.3);

    width: 540rpx;
    box-sizing: border-box;



    margin: auto;

    display: flex;
    justify-content: center;
    align-items: center;



  }



  .opt-item-type-3 {
    font-family: PingFang-SC, PingFang-SC;
    font-weight: 500;
    font-size: 36rpx;
    color: #FFFFFF;
    line-height: 50rpx;
    text-align: center;
    font-style: normal;

    width: 540rpx;
  }

  .opt-item-act {
    height: 90rpx;
    width: 540rpx;
    line-height: 90rpx;

    font-family: PingFang-SC, PingFang-SC;
    font-weight: 500;
    font-size: 60rpx;
    color: #073563;
    // line-height: 90rpx;
    text-align: center;
    font-style: normal;

    // background: linear-gradient( 90deg, rgba(255,255,255,0) 0%, #FFFFFF 58%, rgba(255,255,255,0) 100%);
  }

  .page-prev-p1 {
    position: relative;
    height: 100vh;
    width: 100vw;
    box-sizing: border-box;
    padding-top: 140rpx;

    >.tit-box {
      display: flex;
      flex-direction: column;
      align-items: center;

      // margin-top: 140rpx;
      .row-1 {
        width: 352rpx;
        height: 100rpx;

        .img {
          width: 100%;
          height: 100%;
        }
      }

      .row-2 {
        margin-top: 20rpx;
        width: 433rpx;
        height: 60rpx;

        .img {
          width: 100%;
          height: 100%;
        }
      }
    }

    >.main-wrapper {
      position: relative;
      margin-top: 168rpx;
      height: 440rpx;

      .scroll-opts-pos {
        // height: 516rpx;
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 2;

        .scroll-opts {
          height: 516rpx;

          .scroll-inner-wrapper {
            // padding: 220rpx 0;
            padding: 206rpx 0;
          }
        }
      }

      .abs-act-box {
        position: absolute;
        z-index: 1;
        top: 50%;
        transform: translate(-50%, -50%);
        left: 50%;
        right: 0;

        width: 540rpx;
        height: 90rpx;
        background: linear-gradient(90deg, rgba(255, 255, 255, 0) 0%, #FFFFFF 58%, rgba(255, 255, 255, 0) 100%);
      }
    }

    >.btn-pos {
      position: fixed;
      bottom: 6vh;
      left: 0;
      right: 0;
      z-index: 2;

      display: flex;
      justify-content: center;
      column-gap: 50rpx;
      margin-top: 24rpx;

      .img {
        width: 280rpx;
        height: 100rpx;
      }
    }

  }



  .picker-view {
    width: 540rpx;
    margin: auto;
    height: 440rpx;
    color: rgba(255, 255, 255, 0.5);
    text-align: center;
    line-height: 90rpx;

  }
</style>